<?php
class Default_Model_Notification extends Zend_Db_Table{

	protected $_name = NOTIFICATION_TABLE;
	protected $_primary = 'notification_id';

	private $SENDER_ID = 'sender_id';
	private $RECIEVER_ID = 'receiver_id';
	private $CONCERN_ID = 'concern_id';
	private $TYPE = 'type';
	private $FRIEND_TYPE = "friend";

	protected $db;

	public function __construct(){
		//Goi ket noi voi Zend Db
		$this->db = Zend_Registry::get('connectDB');
	}

	protected $_messageError = null;
	
	// Xoa notify
	public function deleteNotificationByUserId($userId){
		try {
			$this->db->delete(NOTIFICATION_TABLE,$this->SENDER_ID.' = ' . $userId . ' OR '. $this->RECIEVER_ID.' = ' . $userId);
			return true;
		} catch (Exception $e) {
			$this->_messageError = $e->getMessage();
			return false;
		}
	}
	
	public function deleteNotifyConcernByUserId($userId){
		try {
			$this->db->delete(NOTIFICATION_TABLE,$this->CONCERN_ID.' = ' . $userId . ' AND '. $this->TYPE.' = "' . $this->FRIEND_TYPE.'"');
			return true;
		} catch (Exception $e) {
			$this->_messageError = $e->getMessage();
			return false;
		}
	}

	public function getError(){
		return $this->_messageError;
	}
}